﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TagCore;

namespace TagLib
{
    public class TagLibMusic : IMusicTag
    {
        #region Data
        private FileData file;
        private TagLib.File tagFile;
        private TagData tag;
        #endregion

        #region C'tor
        public TagLibMusic()
        {
        }
        #endregion

        #region Public Methods
        public TagCore.FileTypes SupportedTypes()
        {
            return TagCore.FileTypes.mp3 | TagCore.FileTypes.m4a;
        }

        public string Provider()
        {
            return "TagLib";
        }

        public void Load(FileData file)
        {
            this.file = file;
            this.tagFile = TagLib.File.Create(file.File);
            this.tag = new TagData(tagFile.Tag);
        }

        public void Refresh()
        {
            throw new NotImplementedException();
        }

        public void Save()
        {
            tagFile.Save();
        }

        public override string ToString()
        {
            return Provider();
        }
        #endregion

        #region Public Properties
        public IMusicData Data
        {
            get
            {
                return tag;
            }
        }

        public FileData File
        {
            get
            {
                return file;
            }
        }
        #endregion


        public void Rename(string filename)
        {
            throw new NotImplementedException();
        }


        public void Close()
        {
            // ensure any underlying file is closed
            tagFile.Dispose();
        }
    }
}
